import http from '../utils/httpRequest.js'

let testAvatar = "https://thirdwx.qlogo.cn/mmopen/vi_32/Y44BhqAUMialxdAQU19a9m3ciapZGUZL7BRXeSE4gKdF8Qo99wbhaAicUfUw62p2WW6JHFojQiaXuE21iaNWCSWONog/132"
let userListTest = [
    {id: 1, username: Math.random(), name: "testUser1", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 2, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 2, avatar: testAvatar},
    {id: 3, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 3, avatar: testAvatar},
    {id: 4, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 5, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 6, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 7, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 8, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 9, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 10, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 11, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
    {id: 12, username: Math.random(), name: "testUser", phone: "17058179046", sex: 1, status: 1, avatar: testAvatar},
]

// 分页查询
export function getUserList(params) {
    params.path = `/user/list?pageNo=${params.pageNo}&pageSize=${params.pageSize}`
    params.testData = {
        list: userListTest.slice((params.pageNo - 1) * params.pageSize, params.pageNo * params.pageSize),
        total: userListTest.length,
    }
    params.showLoading = false
    http(params)
}

// 激活或冻结用户账号
export function updateUserStatus(params) {
    http({
        ...params,
        method: "PUT",
        path: "/user/status/" + params.userId + "/" + params.newStatus,
        testData: function () {
            userListTest.find(e => {
                return e.id === params.userId
            }).status = params.newStatus
            return true
        },
    })
}

